package com.ch.sys.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import com.ch.sys.filter.SessionUtils;
import com.ch.sys.model.Employee;
import com.ch.sys.model.Function;
import com.ch.sys.model.Role;
import com.ch.sys.service.FunctionService;

/**
 * 页面 导航
 * @author Administrator
 *
 */
@Controller
public class PageController extends BaseController{
	
	@Autowired
	FunctionService functionService;
	
	/**
	 * 后台登录页
	 * @return
	 */
	@RequestMapping(value="/admin/login",method=RequestMethod.GET)
	public String toLoginPage() {
		return "/sys_user/login";
	}
	
	/**
	 * 后台首页
	 * @param request
	 * @return
	 */
	@RequestMapping(value="/admin/index",method=RequestMethod.GET)
	public ModelAndView index(HttpServletRequest request, ModelMap modelMap){
		Employee employee = SessionUtils.get();
		Role role = employee.get("role", Role.class);
		
		List<Function> functions = functionService.findByRole(role.getLong("id"));
		modelMap.addAttribute("functions", functions);
		return new ModelAndView("/admin/index", modelMap);
	}
	
	/**
	 * 角色管理
	 * @param request
	 * @return
	 */
	@RequestMapping(value="/admin/role_manager",method=RequestMethod.GET)
	public String roleManager(HttpServletRequest request){
		return "/role/role_manager";
	}
	
	/**
	 * 后台首页
	 * @param request
	 * @return
	 */
	@RequestMapping(value="/admin/user_manager",method=RequestMethod.GET)
	public String sysUserManager(HttpServletRequest request){
		return "/sys_user/user_manager";
	}
}
